package com.example.first.thread;

import com.example.first.common.Constant;

import java.util.concurrent.*;

/**
 * @Author LSQ
 * @Description 为什么这里可以不用加锁？ 实践表明这些worker里面的成员都不是共享变量
 * @date 2021/11/13 23:23
 * @Version 1.0
 */

public class LearnSynchronized7 {

    public static void main(String[] args) throws InterruptedException {

/*        Thread thread1 = new Thread(new Worker(0, 1));
        Thread thread2 = new Thread(new Worker(100, 200));

        thread1.start();
        thread2.start();

        thread1.join();
        thread2.join();*/

        ExecutorService executorService = new ThreadPoolExecutor(Constant.CORE_POOL_SIZE, Constant.MAX_POOL_SIZE,
                0L, TimeUnit.MILLISECONDS,
                new ArrayBlockingQueue<Runnable>(Constant.QUEUE_CAPACITY));

        Worker worker1 = new Worker(10, 1);
        Worker worker2 = new Worker(9, 2);
        Worker worker3 = new Worker(8, 3);
        Worker worker4 = new Worker(7, 4);
        Worker worker5 = new Worker(6, 5);
        Worker worker6 = new Worker(5, 6);
        Worker worker7 = new Worker(4, 7);
        Worker worker8 = new Worker(3, 8);
        Worker worker9 = new Worker(2, 9);
        Worker worker10 = new Worker(1, 10);

        executorService.submit(worker1);
        executorService.submit(worker2);
        executorService.submit(worker3);
        executorService.submit(worker4);
        executorService.submit(worker5);
        executorService.submit(worker6);
        executorService.submit(worker7);
        executorService.submit(worker8);
        executorService.submit(worker9);
        executorService.submit(worker10);

    }
}
